package 刷题10月.leecodehot100;

public class Solution5 {
    public static String solve (String str1, String str2) {
        // write code here
        StringBuffer stringbuff=new StringBuffer("");
        int i=str1.length()-1,j=str2.length()-1,carry=0;
        while(i>=0||j>=0){
            int n1=i>=0?str1.charAt(i)-'0':0;
            int n2=j>=0?str2.charAt(j)-'0':0;
            int temp=n1+n2+carry;
            carry=temp/2;
            stringbuff.append(temp%2);
            i--;
            j--;
        }
        if(carry==1){
            stringbuff.append(1);
        }
        return stringbuff.reverse().toString();
    }

    public static void main(String[] args) {
        System.out.println(solve("1101","1100"));

    }
}
/*
int x=0;
        int vote=0;
        for(int num:arr){
            if(vote==0)x=num;
            vote+=num==x?1:-1;
        }
        return x;
 */
/*
public int findNum (int[] arr) {
        // write code here
        if(arr==null&&arr.length<1){
            return -1;
        }
        int num=arr[0];
        int count=1;
        for(int i=1;i<arr.length;i++){
            if(num==arr[i]){
                ++count;
            }
            else{
                count--;
                if(count==0){
                    num=arr[i];
                    count=1;
                }
            }
        }
        count=0;
        for(int i=0;i<arr.length;i++){
            if(arr[i]==num){
                count++;
            }
        }
        if(count>=arr.length/2){
            return num;
        }
        return -1;
    }
 */